<template>
  <div id="supOrder">
    <div class="time-box" >
      {{ formatDate1(item.payTime)}}
    </div>
    <div class="center">
      <div class="flexBox">
        <div class="left">
          <p>订单<span> {{item.id}}</span></p>
          <div><b>{{ item.instructionName }}</b><span>&yen;<i>{{ item.payAmount }}</i></span></div>
        </div>
        <div class="cancel color-9" v-if="+item.status === 1">
          已取消
        </div>
        <div class="right" v-else-if="+item.status === 2">
          <span class="color-4c">使用中...</span>
          <p class="color-9">剩余时间：<span class="color-4c">{{ timeAll }}</span></p>
        </div>
        <div class="complete color-2a" v-else-if="+item.status === 3">
          已完成
        </div>
        <div class="cancel color-9" v-else-if="+item.status === 4">
          已失败
        </div>
      </div>
      <div class="footerBox color-9">
        <div class="F-left">
          <p>用户 &nbsp;<span class="color-4c">{{ item.userName }}</span></p>
        </div>
        <div class="F-right">
          <p>手机号 &nbsp;<span class="color-4c">{{ item.phone }}</span></p>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
  import formatDate from '../../../utils/transformTime';

  export default {
    props: {
      item: {
        type: Object,
        require: true,
        default: {}
      }
    },

    data() {
      return {
        timeAll: '',
        t: 0,
        page: 0,
        faultLloading: false,
        noData: false,
        loading: false
      }
    },

    computed: {
    },

    methods: {
      init () {
        let t = this.item.consumeTime * 60000 - (Date.now() - this.item.payTime)
        this.t = parseInt(t / 1000)
        console.log(this.t);
      },
      formatDate1 (argm) {
        return formatDate(new Date(+argm), 'HH:mm:ss');
      },

      // 倒计时？
      timeNum() {
        let timer
        if (+this.item.status === 2) {
          var h = 0;
          var m = 0;
          var s = 0;
          timer = setInterval(() => {
            this.t--
            if (this.t > 0) {
              h = parseInt(this.t / 3600);
              m = parseInt(this.t / 60 % 60);
              s = parseInt(this.t % 60);
              if (m < 10) {
                m = '0' + m
              }
              if (s < 10) {
                s = '0' + s
              }
              this.timeAll = h + '时' + m + '分' + s + '秒';
              if (h < 1) {
                this.timeAll = m + '分' + s + '秒';
              }
             // console.log(this.timeAll);
            } else {
              this.item.status = 3
              clearTimeout(timer)
            }
          }, 1000)
        }
      }
    },

    created () {
      this.init()
      this.timeNum()
    }
  }
</script>

